package com.wodan.zhongjinjicang.common.orm.utils;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.util.Assert;

/**
 * 记录运行时间的bean
 * @ClassName: ExecTimeRecord 
 * @author Administrator
 * @date 2015-7-24 下午8:46:35 
 * @history 
 *
 */
public class ExecTimeRecord {
	/**
	 * 记录的标题
	 */
	private final String label;

	/**
	 * 运行次数汇总
	 */
	private AtomicLong totalExecCount = new AtomicLong(0);

	/**
	 * 执行时间汇总
	 */
	private AtomicLong totalExecTime = new AtomicLong(0);

	/**
	 * 构造函数
	 * @param label
	 */
	public ExecTimeRecord(String label) {
		Assert.hasText(label);

		this.label = label;
	}

	public void record(long currentExecTime) {
		totalExecCount.incrementAndGet();
		totalExecTime.addAndGet(currentExecTime);
	}

	public long getTotalExecCount() {
		return totalExecCount.get();
	}

	public long getTotalExecTime() {
		return totalExecTime.get();
	}

	public long getAvgExecTime() {
		return totalExecTime.get() / totalExecCount.get();
	}

	public String getClassName() {
		return label;
	}
}
